#
# Copyright (C) 2015 Niek Linnenbank
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

Import('build_env')

env = build_env.Clone()

for item in env['LINKUSER']:
    env['LINKFLAGS'].remove(item)

env.Append(LINKFLAGS = env['LINKKERN'])
env.Append(CPPFLAGS = '-D__KERNEL__')

env.UseLibraries(['liballoc', 'libstd', 'libarch', 'libipc'])
env.UseServers(['core', 'filesystem'])
env.TargetProgram('kernel', [ Glob('*.cpp'),
                              Glob('#' + env['BUILDROOT'] + '/kernel/*.cpp'),
                              Glob('#' + env['BUILDROOT'] + '/kernel/intel/*.cpp'),
                              Glob('#' + env['BUILDROOT'] + '/kernel/intel/*.S'),
                              Glob('#' + env['BUILDROOT'] + '/kernel/API/*.cpp') ]
                            , env['boot'])

#
# Boot ISO (LiveCD)
#
cd = env.ISO('#${BUILDROOT}/boot.iso',
           [ '#${BUILDROOT}/kernel/intel/pc/kernel',
             '#${BUILDROOT}/boot.img.gz' ])

# Shortcut to build the ISO.
Alias('iso', cd)

#
# Qemu targets
#
env.Targets(qemu           = 'qemu-system-i386 -cdrom ' + build_env['BUILDROOT'] + '/boot.iso -smp 4 -m 256')
env.Targets(qemu_curses    = 'qemu-system-i386 -cdrom ' + build_env['BUILDROOT'] + '/boot.iso -smp 4 -m 256 -curses')
env.Targets(qemu_serial    = 'qemu-system-i386 -cdrom ' + build_env['BUILDROOT'] + '/boot.iso -smp 4 -m 256 -nographic')
env.Targets(qemu_debug     = 'qemu-system-i386 -cdrom ' + build_env['BUILDROOT'] + '/boot.iso -smp 4 -m 256 -curses -s -S')
env.Targets(qemu_debugs    = 'qemu-system-i386 -cdrom ' + build_env['BUILDROOT'] + '/boot.iso -smp 4 -m 256 -nographic -s -S')
env.Targets(qemu_debug_int = 'qemu-system-i386 -cdrom ' + build_env['BUILDROOT'] + '/boot.iso -smp 4 -m 256 -nographic -s -S -d int,cpu_reset')

#
# Autotester in Qemu
#
env.AutoTester(qemu_test = 'qemu-system-i386 -cdrom ' + build_env['BUILDROOT'] + '/boot.iso -m 256 -nographic')
